package com.aya.simple;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpSession;
import java.io.IOException;

@Controller
public class ResponseController {


    @ResponseBody
    @RequestMapping("session")
    public String hello(HttpSession httpSession) throws IOException {
        return httpSession.getId();
    }


    @ResponseBody
    @RequestMapping("attr/set")
    public String attrSet(HttpSession httpSession, String attr) throws IOException {
        httpSession.setAttribute("name", attr);
        return attr;
    }


    @ResponseBody
    @RequestMapping("attr/get")
    public Object attrGet(HttpSession httpSession) throws IOException {
        Object attr = httpSession.getAttribute("name");
        logger.info("attr name: {}", attr);
        return attr;
    }


    @ResponseBody
    @RequestMapping("attr/none")
    public Object attrGet() throws IOException {
        return "touch session";
    }

    private static final Logger logger = LoggerFactory.getLogger(ResponseController.class);

}
